﻿using System;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;

namespace LMHTX.Modules.DIRECTORY.TEAM.Components
{
    public partial class Team
    {
        public static DataSet SelectTeam_SelectBy_TypeID(Guid moduleID, int typeID)
        {
            const string spName = "p_COOPERATIVE_Team_SelectBy_TypeID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, typeID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet SelectTeam_SelectBy_CareerID(Guid moduleID, int careerID)
        {
            const string spName = "p_COOPERATIVE_Team_SelectBy_CareerID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, careerID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet SelectTeam_SelectBy_AreaID(Guid moduleID, int areaID)
        {
            const string spName = "p_COOPERATIVE_Team_SelectBy_AreaID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, areaID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet SelectAll_AreaName(Guid moduleID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Team_SelectAll_AreaName]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet Search(Guid moduleID, string whereCondition)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Team_Search]";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}
